package com.ruoyi.ade.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.ade.domain.Standard;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.ade.domain.AdeKnowledge;
import com.ruoyi.ade.service.IAdeKnowledgeMgtService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * ADE KnowledgeController
 * 
 * @author wxh
 * @date 2025-06-04
 */
@RestController
@RequestMapping("/ade/AdeKnowledge")
public class AdeKnowledgeController extends BaseController
{
    @Autowired
    private IAdeKnowledgeMgtService adeKnowledgeService;

    @PutMapping("/import")
    public AjaxResult importAdeKnowledge(){
        boolean r = adeKnowledgeService.importAdeKnowledge();
        if(r) return AjaxResult.success();
        return AjaxResult.error("Importing is goning on..");
    }
    @PutMapping("/format")
    public AjaxResult format(){
        boolean r = adeKnowledgeService.format();
        if(r) return AjaxResult.success();
        return AjaxResult.error("Formatting is goning on..");
    }
    /**
     * 查询ADE Knowledge列表
     */
    @PreAuthorize("@ss.hasPermi('ade:AdeKnowledge:list')")
    @GetMapping("/list")
    public TableDataInfo list(AdeKnowledge adeKnowledge)
    {
        startPage();
        List<AdeKnowledge> list = adeKnowledgeService.selectAdeKnowledgeList(adeKnowledge);
        return getDataTable(list);
    }

    /**
     * 导出ADE Knowledge列表
     */
    @PreAuthorize("@ss.hasPermi('ade:AdeKnowledge:export')")
    @Log(title = "ADE Knowledge", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AdeKnowledge adeKnowledge)
    {
        List<AdeKnowledge> list = adeKnowledgeService.selectAdeKnowledgeList(adeKnowledge);
        ExcelUtil<AdeKnowledge> util = new ExcelUtil<AdeKnowledge>(AdeKnowledge.class);
        util.exportExcel(response, list, "ADE Knowledge数据");
    }

    /**
     * 获取ADE Knowledge详细信息
     */
    @PreAuthorize("@ss.hasPermi('ade:AdeKnowledge:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(adeKnowledgeService.selectAdeKnowledgeById(id));
    }

    /**
     * 随机获取一条满足条件的数据
     * @param adeKnowledge
     * @return
     */
    @PostMapping(value = "/random")
    public AjaxResult random(@RequestBody AdeKnowledge adeKnowledge){
        return AjaxResult.success(adeKnowledgeService.selectOneRandomAdeKnowledge(adeKnowledge));
    }

    /**
     * 新增ADE Knowledge
     */
    @PreAuthorize("@ss.hasPermi('ade:AdeKnowledge:add')")
    @Log(title = "ADE Knowledge", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AdeKnowledge adeKnowledge)
    {
        adeKnowledge.setCreateBy(getUsername());
        return toAjax(adeKnowledgeService.insertAdeKnowledge(adeKnowledge));
    }

    /**
     * 修改ADE Knowledge
     */
    @PreAuthorize("@ss.hasPermi('ade:AdeKnowledge:edit')")
    @Log(title = "ADE Knowledge", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AdeKnowledge adeKnowledge)
    {
        adeKnowledge.setUpdateBy(getUsername());
        return toAjax(adeKnowledgeService.updateAdeKnowledge(adeKnowledge));
    }

    /**
     * 删除ADE Knowledge
     */
    @PreAuthorize("@ss.hasPermi('ade:AdeKnowledge:remove')")
    @Log(title = "ADE Knowledge", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(adeKnowledgeService.deleteAdeKnowledgeByIds(ids));
    }
}
